package com.cn.kabalifeuser.ui.order.fragment;

import com.cn.kabalifeuser.api.Api;
import com.cn.kabalifeuser.base.BasePresenter;
import com.cn.kabalifeuser.callback.CacheCallBack;
import com.cn.kabalifeuser.config.Constants;
import com.cn.kabalifeuser.ui.login.bean.MsgBean;
import com.cn.kabalifeuser.ui.release.bean.ReleaseListBean;
import com.cn.kabalifeuser.utils.LoggerUtils;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;

/**
 * Created by 晓林 on 2020/9/7.
 * function:
 */
public class ServiceFragmentsPresenter extends BasePresenter<ServiceFragmentslView> {
    public void onOrderListData(String token, int type, int page, int limit) {
        OkGo.<ReleaseListBean>get(Api.API_SREVUICE_LIST)
                .headers("token", token)
                .params("limit", limit)
                .params("page", page)
                .params("type", type)
                .params("app_type", 1)
                .execute(new CacheCallBack<ReleaseListBean>() {
                    @Override
                    public void onSuccess(Response<ReleaseListBean> response) {
                        super.onSuccess(response);
                        LoggerUtils.e("list：" + response.body());
                        if (isViewAttached())
                            if (response.body().getCode() == Constants.HTTP_SUCCESS)
                                getView().onOrderListSuccess(response.body());
                            else if (response.body().getCode() == Constants.HTTP_AGAIN_LOGIN)
                                getView().onReLoggedIn(response.body().getMsg());
                            else
                                getView().onError(response.body().getMsg());
                    }
                });
    }

    /**
     * 服务申述退款
     * @param token
     * @param service_id
     * @param content
     */
    public void onOrderTuiData(String token, int service_id, String content) {
        OkGo.<MsgBean>post(Api.API_SREVUICE_TUI)
                .headers("token", token)
                .params("content", content)
                .params("service_id", service_id)
                .execute(new CacheCallBack<MsgBean>() {
                    @Override
                    public void onSuccess(Response<MsgBean> response) {
                        super.onSuccess(response);
                        LoggerUtils.e("list：" + response.body());
                        if (isViewAttached())
                            if (response.body().getCode() == Constants.HTTP_SUCCESS)
                                getView().onOrderTuiSuccess(response.body());
                            else if (response.body().getCode() == Constants.HTTP_AGAIN_LOGIN)
                                getView().onReLoggedIn(response.body().getMsg());
                            else
                                getView().onError(response.body().getMsg());
                    }
                });
    }

    /**
     * 申请退款
     *
     * @param token
     * @param service_id
     */
    public void onRefundDepositData(String token, int service_id) {
        OkGo.<MsgBean>post(Api.API_SREVUICE_REFUND)
                .headers("token", token)
                .params("service_id", service_id)
                .execute(new CacheCallBack<MsgBean>() {
                    @Override
                    public void onSuccess(Response<MsgBean> response) {
                        super.onSuccess(response);
                        LoggerUtils.e("退款：" + response.body());
                        if (isViewAttached())
                            if (response.body().getCode() == Constants.HTTP_SUCCESS)
                                getView().onRefundDepositSuccess(response.body());
                            else if (response.body().getCode() == Constants.HTTP_AGAIN_LOGIN)
                                getView().onReLoggedIn(response.body().getMsg());
                            else
                                getView().onError(response.body().getMsg());
                    }
                });
    }

    /**
     * 支付宝和微信
     *
     * @param token
     * @param service_id
     * @param type
     */
    public void onPayGoData(String token, int service_id, String money, int type) {
        OkGo.<String>post(Api.API_SREVUICE_PAY)
                .headers("token", token)
                .params("money", money)
                .params("type", type)
                .params("service_id", service_id)
                .execute(new CacheCallBack<String>() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        super.onSuccess(response);
                        LoggerUtils.e("立即支付：" + response.body());
                        getView().onPaySuccess(response.body());
                    }
                });
    }


}
